package com.bjdd.jdy.ui.commitCard;

import com.bjdd.jdy.util.Event;
import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.T;

import java.util.Map;

import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/4/10.
 */

public class CommitPresenter extends CommitContract.Presenter {
    @Override
    public void commit(String token, Map<String,String> params,Map<String,RequestBody> photos) {
        L.d("提交身份信息");
        showLoadingDialog(false);
        rxManager.add(model.getCommitModel(token,params,photos)
                .subscribe(result -> {
                    hideLoadingDialog();
                    if (!result.isError()){
                        view.commitSuccess(result);
                    }else {
                        T.show(result.getMsg());
                    }
                },e -> {
                    hideLoadingDialog();
                    T.show("提交资料失败:"+e.getMessage());
                }));
    }

    @Override
    public void getArea(String token) {
        rxManager.add(model.getAreaModel(token)
        .subscribe(result -> {
            if (!result.isError()){
                if (!result.isError()){
                    view.setArea(result.getData());
                }else {
                    T.show(result.getMsg());
                }
            }
        },e -> {
            T.show("城市数据加载错误");
            L.d("城市数据错误："+e.getMessage());
        }));
    }

    @Override
    public void getTools(String token) {
        rxManager.add(model.getTools(token)
        .subscribe(result -> {
            if (!result.isError()){
                view.setTools(result.getData());
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            T.show("交通工具加载错误");
        }));
    }

    @Override
    public void onStart() {
        if (SpUtil.getUser() == null || SpUtil.getUser().equals("") || SpUtil.getUser().getCarrierId() == null) {
            JumpUtil.toLogin(context);
            return;
        }
    }
}
